#include <fann.h>
#include <cstdio>
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	FILE *inF = fopen ("../Patients/train.fndata", "r");

	int entrs, inputs, outs;
	
	fscanf (inF, "%d %d %d", &entrs, &inputs, &outs);
	struct fann *ann = fann_create_from_file("cell_classify.net");
	
	int right = 0;
	int wrong = 0;
	

	int mat[3][3];
	for(int i=0; i<3; i++){
                mat[i][0]= mat[i][1]= mat[i][2]=0;
        }
	
	
	for (int j=0; j< entrs; j++){
		float frequencies[inputs];
		
		for (int i=0; i<inputs; i++) {
			fscanf (inF, "%f", &frequencies[i]);
		}
		int o[outs];
		for (int i=0; i<outs; i++ ) {
			fscanf(inF, "%d", &o[i]);
		}
		/*
		for (int i=0; i<inputs; i++)
		{
			printf ("%f\t", frequencies[i]);
		}
		printf ("\n");*/
		int sugn = 0;
		double max = 0;
		float *output = fann_run(ann, frequencies);
		for (int i=0; i<outs; i++) {
			printf ("%.2f\t", output[i]);
			if (output[i]>max)
			{
				max = output[i];
				sugn = i;
			}
		}
		std::cout << "\t\t";
		int realn = 0;
		max = 0;
		for (int i=0; i<outs; i++) {
			printf ("%d\t", o[i]);
			if (o[i]>max)
			{
				max = o[i];
			realn = i;
			}
		}
		
		if (realn == sugn) {
			right++;
			printf ("Right");
		} else {
			wrong++;
			printf ("Wrong");
		}
		std::cout << std::endl;
		mat[realn][sugn]++;
	}
	for(int i=0; i<3; i++){
		printf ("%d %d %d\n", mat[i][0], mat[i][1], mat[i][2]);
	}
	printf ("Right = %d, wrong = %d, Wrong percent = %.2f%%\n", right, wrong, (double)wrong/(right+wrong)*100);
}

